#ifndef REQUEST_H
#define REQUEST_H 1

#include "main.h"
#include "bool.h"
#include "string.h"
#include "dict.h"
#include "cookie.h"

#define QUERY_LEN  32
#define METHOD_LEN 8
#define DOC_LEN    128

#define NOTFOUND_TEXT "<html>\n<body>\n<h1>File not found ..</h1>\n</body>\n</html>"
#define UNKNOWN_TEXT "Unknown error ..\n"
#define KEY_QRY "query"
#define KEY_URI "uri"

typedef struct __ncattr__ request {
  int thrd_num;
  size_t req_num;
  char *qry;
  char *method;
  char *doc_uri;
  void *__unused;
  bool static_req;
  dict_t *http_hdr;
} request_t;

typedef int (*reqhndl_cb_t)(struct request *rq, string_t *output, dict_t *hdr, ck_map_t cookies);


request_t *
request_init(int thrdnum, const char *qry, const char *method, const char *doc_uri, void *__unused, bool static_req, dict_t *http_hdr);

void
request_free(request_t *req);

#if defined(ENABLE_DEBUG) && defined(ENABLE_REQDBG)
void
print_request_debug(request_t *fr);
#endif

size_t
requests_processed(void);

void
set_request_handler(reqhndl_cb_t __request_handler_cb);

int
process_request(struct request *fr);

#endif
